$(function() {
	var mainForm = $('#main-form');

	new Upload({
		elem: 'add-img-btn',
		url: '/Api/Upload/ajax_more_img',
		name: 'Filedata[]',
		formId: 'upload-form',
		inputId: 'file-upload-input'
	});

	//选择颜色插件
    $("#spectrum").spectrum({
        preferredFormat: "rgb",
        showPalette: true,
        showInput: true,
        color: '#82C8BC',
        palette: [
            ['black', 'white', 'blanchedalmond'],
            ['rgb(255, 128, 0);', 'hsv 100 70 50', 'lightyellow']
        ]
    });

    $("#spectrum").on("change.spectrum", function (e, color) { 
        $("input[name='background']").val(color.toHexString());
    });
    

	mainForm.validate();
	mainForm.on('submit', function() {
		try {
			if(mainForm.valid()) {
				mainForm.submitForm();
			}
		}catch(e) {
			console.error(e);
		}

		return false;
	});
});